function tab()
{
	$('#tab_info').find("span").mouseover(function()
	{
		$('#tab_info').find("span").removeClass("tab-front");
		$('#tab_info').find("span").addClass("tab-back");
		$(this).removeClass("tab-back");
		$(this).addClass("tab-front");
		var target = $('#' + this.id+'le');
		if (target.size() > 0) 
		{
			$("table[id$='-table']").hide()
			//$('#tabbody-div').find("table").hide();
			target.show();
		} 
	}); 
}

function create_FCKedito(value)
{
	var oFCKeditor          = new FCKeditor(value);      //创建FCK对象
	oFCKeditor.Height      = 400;        //设置FCK显示高度
	oFCKeditor.Width      = 750;        //设置FCK显示宽度
	oFCKeditor.BasePath   = "../../fckeditor/";    //指定编辑器路径，要加载fckeditor/editor/fckeditor.html
	oFCKeditor.ReplaceTextarea(); 
}

function create()
{
	var arr = ['techSpec_content_table','product_guide_content'];
	$.each(arr, function(key, value) 
	{ 
		create_FCKedito(value);
	}
	); 
	tab();
}

function GetCBSDate()
{
	var product_cbsid = $("#product_cbsid").val();
	var form_action=$("#product_form").attr("action");
	if(product_cbsid.replace(/(^\s*)|(\s*$)/g, "")!="")
	{
		$("#product_sn").val("");
		$("#product_version").val("");
		$("#product_name").val("");
		$("#product_price").val("");
		$("#product_brand").val("")
	
		$.post("./product.php?action=GetCBSData",{pcbs_id:product_cbsid,form_action:'./product.php?action=AddProduct'},function(data)
		{
			var product_date=data;
			if(product_date['message']=='success')
			{
				$("#product_sn").val(product_date['product_sn']);
				$("#product_version").val(product_date['sale_version']);
				$("#product_name").val(product_date['product_name']);
				$("#product_price").val(product_date['price']);
				$("#product_brand").val(product_date['brand_name']);
			}
			else
			{
				alert(product_date['message']);
				$("#product_cbsid").val('');
				$("#product_cbsid").focus();
			}
		},'json');
	}
	else
	{
		alert("请输入CBS产品ID!");
		$("#product_cbsid").focus();
	}
}

function save_product()
{
	if(Util.ValiForm.formValiState())
	{
		$("#product_form").submit();
	}
}

function reset_product()
{
	$("#product_cbsid").attr("readonly","");
}

function getproductlist()
{
	var product_list = $("#product_recomm").val();
	jIframe('', '所有产品列表', {
	width: 750,
	height: 345,
	src: './product.php?action=RecommProduct&product_list='+product_list,
	ID: 'all_product',
	box_btn:true,
	callback:add_okbtn
	});
}

function getproductlisttwo()
{
	var product_list = $("#product_rel").val();
	var product_platform = $("#product_platform").val();
	
	var product_id = $("#product_id").val();
	
	jIframe('', '所有产品列表', {
	width: 750,
	height: 345,
	src: './product.php?action=RecommProductTwo&product_list='+product_list+'&product_platform='+product_platform+'&product_id='+product_id,
	ID: 'all_product_two',
	box_btn:true,
	callback:add_okbtn_two
	});
}


function add_okbtn()
{
	var cnt = document.getElementById("all_product").contentWindow.get_checked_product();
	$("#product_recomm").val(cnt);
	jClose();
}

function add_okbtn_two()
{
	var cnt = document.getElementById("all_product_two").contentWindow.get_checked_product();
	$("#product_rel").val(cnt);
	jClose();
}

function  add_feature(type)
{
	$('#button_feature').css('margin-left','0px');
	$('#button_more_feature').css('margin-left','0px');	 
	if(type == 1)
	{
		var feature_start = parseInt($("#feature_start").val())+1; 
		
		var str = '';
		str += '<tr><td align="right">Key Feature'+feature_start+'标题：</td><td width="300"><input type="text" style="width:400px;" id="title_feature'+feature_start+'" name="title_feature'+feature_start+'" /></td></tr>';
		
		str += '<tr><td align="right">Key Feature'+feature_start+'描述：</td><td ><textarea size="50" style="margin-left:0px;width:400px;height:80px;overflow:hidden;" id="description_feature'+feature_start+'" name="description_feature'+feature_start+'"/> </textarea></td></tr>';
		
		str += '<tr ><td align="right" >Key Feature'+feature_start+'小配图：</td><td ><input type="text" style="width:400px;" id="image_min_feature'+feature_start+'" name="image_min_feature'+feature_start+'"/><span style="color:#FF0000; margin-left:20px;margin-top:20px;">(备注：请填写URL绝对地址)</span></td></tr>';
		
		if( brand != 'iskysoft') str += '<tr ><td align="right">Key Feature'+feature_start+'大配图：</td><td ><input type="text" style="width:400px;" id="image_max_feature'+feature_start+'" name="image_max_feature'+feature_start+'" /><input type="hidden" name="feature_id'+feature_start+'" value="0" /><span style="color:#FF0000; margin-left:20px;margin-top:20px;">(备注：请填写URL绝对地址)</span></td></tr>';
		
		str += '<tr><td align="right">Key Feature'+feature_start+'排序：</td><td ><input type="text"  value="'+feature_start+'" style="width:400px;" id="feature_order'+feature_start+'" name="feature_order'+feature_start+'" /></td></tr>';
		
		str += '<tr style="height:30px;"><td>&nbsp;</td><td>&nbsp;</td></tr>';
		
		$('#add_feature').before( str ); 
		
		$("#feature_start").val(feature_start);
		
		if(feature_start == 15)
		{
			$("#add_feature").css('display','none');
		}
		
	}else if(type == 2){
		var more_feature_start = parseInt($("#more_feature_start").val())+1; 
		
		$('#add_more_feature').before('<tr ><td ><div style="margin-left:200px; width:120px; margin-top:50px;">More Feature'+more_feature_start+
		'标题：</div></td><td ><input type="text" name="title_more_feature'+more_feature_start+'" id="title_more_feature'+more_feature_start+
		'" style="width:400px; margin-top:40px;" /></td></tr><tr ><td ><div style="margin-left:200px; width:150px; margin-top:20px;">'+
		'<span style="">More Feature'+more_feature_start+'描述：</span></div></td><td ><textarea name="description_more_feature'+more_feature_start+
		'" id="description_more_feature'+more_feature_start+'" size="50" style="margin-left:0px;margin-top:10px; width:400px; '+	
		'height:70px;overflow:hidden; " /> </textarea></td></tr> <tr ><td ><div style="margin-left:200px;width:120px; margin-top:20px;">'+
		'More Feature'+more_feature_start+'配图：</div></td><td ><input type="text" name="image_more_feature'+more_feature_start+
		'"  id="image_more_feature'+more_feature_start+'" style="width:400px;margin-top:20px; " /><input type="hidden" '+
		'name="more_feature_id'+more_feature_start+'" value="0" /><span style="color:#FF0000; '+
		'margin-left:20px;margin-top:20px;">(备注：请填写URL绝对地址)</span></td></tr><tr ><td >'+
		'<div style="margin-left:200px; width:120px; margin-top:20px;">'+
		'More Feature'+more_feature_start+'排序：</div></td><td ><input type="text" value="'+more_feature_start
		+'" style="width:400px; margin-top:20px;" id="feature_more_order'+more_feature_start+'"'+
		'name="feature_more_order'+more_feature_start+'" /></td></tr>');
		
		$("#more_feature_start").val(more_feature_start);
		if(more_feature_start == 15)
		{
		
			$("#add_more_feature").css('display','none');
		}
	}else if( type == 3 ){
		var other_feature_start = parseInt($("#other_feature_start").val())+1; 
		
		$('#add_other_feature').before('<tr ><td ><div style="margin-left:200px; width:120px; margin-top:50px;">Other Feature'+other_feature_start+
		'标题：</div></td><td ><input type="text" name="title_other_feature'+other_feature_start+'" id="title_other_feature'+other_feature_start+
		'" style="width:400px; margin-top:40px;" /></td></tr><tr ><td ><div style="margin-left:200px; width:150px; margin-top:20px;">'+
		'<span style="">other Feature'+other_feature_start+'描述：</span></div></td><td ><textarea name="description_other_feature'+other_feature_start+
		'" id="description_other_feature'+other_feature_start+'" size="50" style="margin-left:0px;margin-top:10px; width:400px; '+	
		'height:70px;overflow:hidden;" /> </textarea></td></tr> <tr ><td ><div style="margin-left:200px;width:120px; margin-top:20px;">'+
		'other Feature'+other_feature_start+'配图：</div></td><td ><input type="text" name="image_other_feature'+other_feature_start+
		'"  id="image_other_feature'+other_feature_start+'" style="width:400px;margin-top:20px; " /><input type="hidden" '+
		'name="other_feature_id'+other_feature_start+'" value="0" /><span style="color:#FF0000; '+
		'margin-left:20px;margin-top:20px;">(备注：请填写URL绝对地址)</span></td></tr><tr ><td >'+
		'<div style="margin-left:200px; width:120px; margin-top:20px;">'+
		'other Feature'+other_feature_start+'排序：</div></td><td ><input type="text" value="'+other_feature_start
		+'" style="width:400px; margin-top:20px;" id="feature_other_order'+other_feature_start+'"'+
		'name="feature_other_order'+other_feature_start+'" /></td></tr>');
		
		$("#other_feature_start").val(other_feature_start);
	}
}

function inarray(obj,arr)
{
	if(typeof obj == 'string')
	{
		for(var i in arr) 
		{
			if(arr[i] == obj) 
			{
			return true;
			}
		}
	}
	return false;
} 

function  product_form_submit()
{

	var feature_start = parseInt($("#feature_start").val());
	var more_feature_start = parseInt($("#more_feature_start").val());
	var product_cbsid = $("#product_cbsid").val();
	var  product_name = $("#product_name").val();
	var  type = $("#type").val();
	var  video_url = $("#video_url").val().replace(/(^\s*)|(\s*$)/g, "");
	var  video_width = $("#video_width").val().replace(/(^\s*)|(\s*$)/g, "");
	var  video_higth = $("#video_higth").val().replace(/(^\s*)|(\s*$)/g, "");
	
	if(type == 'add')
	{
		if(product_cbsid.replace(/(^\s*)|(\s*$)/g, "")=="")
		{
			alert("请输入CBS产品ID!");
			$("#product_cbsid").focus();
			return false;
		}
	
		if(product_name.replace(/(^\s*)|(\s*$)/g, "")=="")
		{
			alert("CBS产品名称不能为空!");
			$("#product_cbsid").focus();
			return false;
		}
	}
	
	if($("#product_rel").val().replace(/(^\s*)|(\s*$)/g, "")!="") 
	{
	
		if($("#product_id").val() == $("#product_rel").val())
		{
			alert("对应Win/Mac产品不能选择自己！");
			return false;
		}
	}
	
	
	if(video_url.replace(/(^\s*)|(\s*$)/g, "")!="") 
	{
		var arr = video_url.split(".");
		var arr_length  = arr.length;
		var video_type  = new Array("swf", "flv", "mov",'m4v'); 
	
		if(video_url.indexOf('http://www.youtube.com/') == -1)
		{
			if(!inarray(arr[arr_length-1],video_type))
			{
				alert("视频格式不对！");
				$("#video_url").focus();
				return false;
			}
		}
	/*
		if(video_width.replace(/(^\s*)|(\s*$)/g, "") == "") 
		{
			alert("视频宽不能为空！");
			$("#video_width").focus();
			return false;
		}
		if(video_higth.replace(/(^\s*)|(\s*$)/g, "") == "") 
		{
			alert("视频高不能为空！");
			$("#video_higth").focus();
			return false;
		}
	*/
	
	}
	
	/*
	if(video_width.replace(/(^\s*)|(\s*$)/g, "") != "") 
	{
		if(video_url.replace(/(^\s*)|(\s*$)/g, "") =="") 
		{
		alert("视频格式不对！");
		$("#video_url").focus();
		return false;
		}
		var   r   =   /^\+?[1-9][0-9]*$/;　　//正整数 
		if(!r.test(video_width))
		{
			alert("视频宽应该为大于0的正整数！");
			$("#video_width").focus();
			return false;
		}
	}

	if(video_higth.replace(/(^\s*)|(\s*$)/g, "") != "") 
	{
		if(video_url.replace(/(^\s*)|(\s*$)/g, "") =="") 
		{
			alert("视频格式不对！");
			$("#video_url").focus();
			return false;
		}
		var   r   =   /^\+?[1-9][0-9]*$/;　　//正整数 
		if(!r.test(video_higth))
		{
			alert("视频高应该大于0的正整数！");
			$("#video_higth").focus();
			return false;
		}
	}*/
	return true;
}